package com.ruoyi.carService.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.api.domain.CarOrders;
import com.ruoyi.carService.service.ICarOrdersService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 订单Controller
 * 
 * @author ruoyi
 * @date 2024-09-09
 */
@RestController
@RequestMapping("/orders")
public class CarOrdersController extends BaseController
{
    @Autowired
    private ICarOrdersService carOrdersService;

    /**
     * 查询订单列表
     */
    @RequiresPermissions("carService:orders:list")
    @GetMapping("/list")
    public TableDataInfo list(CarOrders carOrders)
    {
        startPage();
        List<CarOrders> list = carOrdersService.selectCarOrdersList2(carOrders);
        System.out.println(list);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @RequiresPermissions("carService:orders:export")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarOrders carOrders)
    {
        List<CarOrders> list = carOrdersService.selectCarOrdersList(carOrders);
        ExcelUtil<CarOrders> util = new ExcelUtil<CarOrders>(CarOrders.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 获取订单详细信息
     */
    @RequiresPermissions("carService:orders:query")
    @GetMapping(value = "/{ordId}")
    public AjaxResult getInfo(@PathVariable("ordId") Long ordId)
    {
        return success(carOrdersService.selectCarOrdersByOrdId(ordId));
    }

    /**
     * 新增订单
     */
    @RequiresPermissions("carService:orders:add")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarOrders carOrders)
    {
        return toAjax(carOrdersService.insertCarOrders(carOrders));
    }

    /**
     * 修改订单
     */
    @RequiresPermissions("carService:orders:edit")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarOrders carOrders)
    {
        return toAjax(carOrdersService.updateCarOrders(carOrders));
    }

    /**
     * 删除订单
     */
    @RequiresPermissions("carService:orders:remove")
    @Log(title = "订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ordIds}")
    public AjaxResult remove(@PathVariable Long[] ordIds)
    {
        return toAjax(carOrdersService.deleteCarOrdersByOrdIds(ordIds));
    }



}
